package leetcode.code1588;




public class Solution2 extends Solution1588 {

	@Override
	public int sumOddLengthSubarrays(int[] arr) {
		int len = arr.length;// 数组长度
		int sum = 0;// 累加和
		for (int i = 0; i < len; i++) {
			int il1 = (i + 1) >> 1;// 左边奇数
			int ir1 = (len - i) >> 1;// 右边奇数
			int il2 = (i >> 1) + 1;// 左边偶数选择的种数
			int ir2 = ((len - 1 - i) >> 1) + 1;// 右边偶数选择的种数
			int times = ir1 * il1 + ir2 * il2;
			sum += arr[i] * (times);
		}
		return sum;
	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		System.out.println("-------");
		so.debug2();
		System.out.println("-------");
		so.debug3();
		System.out.println("-------");

//		int result = so.sumOddLengthSubarrays(new int[] { 1, 4, 2, 5, 3 });
//		System.out.println(result);
//		so.sumOddLengthSubarrays(new int[] { 1, 4, 2, 5, 3, 6, 8 });
	}

}
